package com.dom.domweb.modular.controller;

import com.dom.common.model.vo.sale.*;
import com.dom.domweb.common.RspModel;
import com.dom.domweb.common.TabPager;
import com.dom.domweb.modular.service.SaleOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.info.InfoPropertiesInfoContributor;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.jws.WebParam;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 销售订单控制器
 * @author zhuwei
 * @Date 2018-11-17
 */
@Slf4j
@RestController
@RequestMapping("/sale")
public class SaleOrderController {

    @Autowired
    private SaleOrderService saleOrderService;

    /**
     * 查询销售订单列表
     * @param limit 每页行数
     * @param page 当前页数
     * @param exchStartDate 交易开始时间
     * @param exchEndDate 交易结束时间
     * @param sendStartDate 发货开始时间
     * @param sendEndDate 发货结束时间
     * @param custCode 客户编码
     * @param custName 客户名称
     * @param saleType 销售类型
     * @return
     */
    @RequestMapping("/getSaleOrderList")
    public TabPager getMarketOrderList(@RequestParam("limit")int limit,
                    @RequestParam("page")int page,
                    @RequestParam("exchStartDate") String exchStartDate,
                    @RequestParam("exchEndDate")String exchEndDate,
                    @RequestParam("sendStartDate")String  sendStartDate,
                    @RequestParam("sendEndDate")String  sendEndDate,
                    @RequestParam("custCode")String  custCode,
                    @RequestParam("custName")String  custName,
                    @RequestParam("saleType")String  saleType //,
//                    @RequestParam("orderType")String  orderType
                                       ) {
        M019R r = new M019R();
        r.setPn(page);
        r.setPs(limit);
        r.setCustCode(custCode);
        r.setCustName(custName);
        r.setSendEndDate(sendEndDate);
        r.setSendStartDate(sendStartDate);
        r.setExchEndDate(exchEndDate);
        r.setExchStartDate(exchStartDate);
//        r.setOrderType(orderType);
        r.setSaleType(saleType);
        M019A m019A = saleOrderService.findMarketOrderList(r);
        return new TabPager(m019A.getSaleOrderData(),m019A.getTotalNum());
    }

    /**
     *  新增销售订单
     * @param request 新增销售订单对象
     * @return
     */
    @RequestMapping(value="/insertSaleOrder", method = RequestMethod.POST)
    public RspModel insertSaleOrder(@RequestBody M010R request){
        String saleId = saleOrderService.insertSaleOrder(request);
        return new RspModel(saleId);
    }

    /**
     *  查询销售订单明细列表
     * @param keyId 销售订单id
     * @return
     */
    @RequestMapping(value="/updateSaleOrderPage", method = RequestMethod.POST)
    public RspModel findUpdateSaleOrderPage(@RequestParam("keyId")String keyId){
        M013A result = saleOrderService.findUpdateSaleOrderPage(keyId);
        return new RspModel(result);
    }

    /**
     * 逻辑删除销售订单
     * @param keyId 销售订单id
     * @return
     */
    @RequestMapping(value = "/saleOrderDel",method = RequestMethod.POST)
    public RspModel saleOrderDel(@RequestParam("keyId") String keyId){
        boolean isTure = saleOrderService.saleOrderDel(keyId);
        RspModel model = new RspModel("RSP000000","销售订单删除成功！");
        if(!isTure){
            model.setRspCode("RSP000001");
            model.setRspMsg("销售订单删除失败！");
        }
        return model;
    }

    @RequestMapping(value = "/saleOrderModify", method = RequestMethod.POST)
    public RspModel saleOrderModify(@RequestBody M012R request){
        return saleOrderService.saleOrderModify(request);
    }
}
